﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GameSchool.Extra;
using System.ComponentModel.DataAnnotations;

namespace GameSchool.Models.OnTheFlyModels
{
    /// <summary>
    /// CourseOverviewItem geymir helstu upplýsingar 
    /// sem snúa að ákveðnum notanda um tiltekið námskeið
    /// </summary>  

    [NotMapped]
    public class CourseOverviewItem
    {
        private int m_personId;

        public CourseOverviewItem()
        { 
        }

        public CourseOverviewItem(int? personId, Course course)
        {
            this.CourseId = course.CourseId;
            this.CourseName = course.CourseName;
            this.CourseDescription = course.Description;
            this.CourseState = course.StateType;
            this.CourseECTS = course.Ects;

            m_personId = personId.Value;

            ICollection<StudentCourse> studentInCourse = course.Students.Where(x => x.StudentId == personId && x.Active).ToList();
            // Finnum út hvort hann sé skráður í þennan kúrs.
            if (studentInCourse.Count() > 0)
            {
                if (studentInCourse.First().Completed)
                {
                    // Notandi er skráður  sem nemandi á þetta námskeið - en hefur lokið við það..
                    RegType = CustomTypes.CourseRegType.Completed;
                }
                else
                {
                    // Notandi er skráður  sem nemandi á þetta námskeið.
                    RegType = CustomTypes.CourseRegType.Student;
                }
            }
            else if (course.Teachers.Where(x => x.TeacherId == personId && x.Active).Count() > 0)
            {
                // Notandi er skráður sem kennari á þetta námskeið.
                RegType = CustomTypes.CourseRegType.Teacher;
            }
            else
            {
                RegType = CustomTypes.CourseRegType.NotParticipating;
            }

        }

        public int CourseId { get; set; }

        public string CourseName { get; set; }

        public string CourseDescription { get; set; }

        public CustomTypes.CourseStateType CourseState { get; set; }

        public int CourseECTS { get; set; }

        public Models.OnTheFlyModels.LevelParticipateInfoList LevelParticipatingInfos { get; set; }
        
        public CustomTypes.CourseRegType RegType { get; set; }
    }
}